home *** CD-ROM | disk | FTP | other *** search
- /********************************************************************************/
- /* */
- /* control.c - control request processing. */
- /* */
- /* Richard W. Mincher. February 19, 1990. */
- /* */
- /* Copyright © 1990 Apple Computer, Inc. All rights reserved. */
- /* */
- /********************************************************************************/
-
- #include "AROSE.h"
- #include "os.h"
- #include "managers.h"
-
- #include "ARDriver.h"
- #include "ARTask.h"
-
- static unsigned short csStuff[12];
-
- ControlCall()
- {
- NetCopy( msg->mFrom, msg->mDataPtr, msg->mTo, csStuff, 24 );
- #ifdef DEBUG
- printf("Control received. mDataPtr=%x, mDataSize=%x, csCode=%04.4x\n",
- msg->mDataPtr, msg->mDataPtr, csStuff[0] );
- #endif DEBUG
- msg->mStatus = 0;
- switch( csStuff[0] )
- {
- case 1: /* KillIO */
- KillIO();
- break;
- case 8: /* Reinitialize */
- Reconfigure();
- break;
- case 9: /* New Buffer */
- break;
- case 10: /* Hankshake */
- SetHandShake();
- break;
- case 11: /* Clear Break */
- ClearBreak();
- break;
- case 12: /* Set Break */
- SetBreak();
- break;
- case 13: /* Baud Rate */
- SetBaudRate();
- break;
- case 14: /* More Handshake */
- SetHandShake();
- break;
- case 16: /* Misc. Options */
- SetMiscOpt();
- break;
- case 17: /* Assert DTR */
- AssertDTR();
- break;
- case 18: /* Negate DTR */
- NegateDTR();
- break;
- case 19: /* Parity Replace */
- SetPEChar();
- break;
- case 20: /* Parity w/ Alt */
- SetPEAltChar();
- break;
- case 21: /* Force XOFF */
- ForceXOff();
- break;
- case 22: /* Clear XOFF */
- ClearXOff();
- break;
- case 23: /* XON if XOFF */
- SendXOnIff();
- break;
- case 24: /* Send XON */
- SendXOn();
- break;
- case 25: /* XOFF if XON */
- SendXOffIff();
- break;
- case 26: /* Send XOFF */
- SendXOff();
- break;
- case 27: /* Reset */
- ResetSCC();
- break;
- default:
- msg->mStatus = -17; /* controlErr */
- }
- }
-
-
- //
- // Control 1 - Kill IO.
- //
-
- KillIO()
- {
- short s;
- message *m;
- tid_type temp;
-
- // Reset SCC pointers.
-
- s = Spl(7);
- G->txCount = G->txTickle = 0;
- G->txIn = G->txOut = G->txFirst;
- G->rxCount = G->rxMax;
- G->rxTickle = 0;
- G->rxIn = G->rxOut = G->rxFirst;
- G->sRxCount = 0;
- G->sTxCount = 0;
- (void)Spl(s);
-
- // Send back write requests.
-
- while(m = G->txQHead)
- {
- G->txQHead = G->txQHead->mNext;
- temp = m->mFrom;
- m->mFrom = m->mTo;
- m->mTo = temp;
- m->mCode |= 1;
- m->mStatus = -27;
- Send( m );
- }
-
- // Send back read requests.
-
- while(m = G->rxQHead)
- {
- G->rxQHead = G->rxQHead->mNext;
- temp = m->mFrom;
- m->mFrom = m->mTo;
- m->mTo = temp;
- m->mCode |= 1;
- m->mStatus = -27;
- Send( m );
- }
-
- }
-
- //
- // Control 8 - Reconfigure.
- //
- Reconfigure()
- {
- short baudConst, s;
-
- s = Spl(7);
- baudConst = (((csStuff[1] & 0x3FF) + 2) << 1) - 2;
- G->baudLow = baudConst & 0xFF;
- G->baudHigh = (baudConst >> 8) & 0xFF;
- G->lastWR4 = ((csStuff[1] >> 12) & 0x0F) | 0x40;
- G->lastWR3 = ((csStuff[1] >> 4) & 0xC0) | 0x01;
- G->lastWR5 = ((csStuff[1] >> 5) & 0x60) | 0x08;
- switch( csStuff[1] & 0xC00 )
- {
- case 0x000:
- G->charMask = 0x1F;
- break;
- case 0x400:
- G->charMask = 0x7F;
- break;
- case 0x800:
- G->charMask = 0x3F;
- break;
- case 0xC00:
- G->charMask = 0xFF;
- break;
- }
- (void)Spl(s);
- #ifdef DEBUG
- printf("Low=%x; High=%x; wr3=%x; wr4=%x; wr5=%x\n",
- G->baudLow, G->baudHigh, G->lastWR3, G->lastWR4, G->lastWR5 );
- #endif DEBUG
- InitSCC();
- }
-
- //
- // Control 10/14 - Set handshake options.
- //
-
- SetHandShake()
- {
- short s;
-
- s = Spl(7);
- G->swhs = (csStuff[1] >> 8) & 0xFF;
- G->hwhs = csStuff[1] & 0xFF;
- G->xOnChar = (csStuff[2] >> 8) & 0xFF;
- G->xOffChar = csStuff[2] & 0xFF;
- G->options = (csStuff[3] >> 8) & 0xFF;
- G->postOptions = csStuff[3] & 0xFF;
- G->inSwHs = (csStuff[4] >> 8) & 0xFF;
- G->inHwHs = csStuff[4] & 0xFF;
- (void)Spl(s);
- if ((csStuff[0] == 14) && G->inHwHs)
- AssertDTR();
- #ifdef DEBUG
- printf("swhs=%x; hwhs=%x; xOnChar=%x; xOffChar=%x\n",
- G->swhs, G->hwhs, G->xOnChar, G->xOffChar );
- printf("options=%x;postOptions=%x;inSwHs=%x;inHwHs=%x\n",
- G->options, G->postOptions, G->inSwHs, G->inHwHs );
- #endif DEBUG
-
- }
-
- //
- // Control 11 - Clear BREAK.
- //
- ClearBreak()
- {
- short s;
-
- s = Spl(7);
- *SCCControl = 0x05;
- *SCCControl = G->lastWR5;
- (void)Spl(s);
- }
-
- //
- // Control 12 - Set BREAK.
- //
- SetBreak()
- {
- short s;
-
- s = Spl(7);
- *SCCControl = 0x05;
- *SCCControl = G->lastWR5 | 0x10;
- (void)Spl(s);
- }
-
- //
- // Control 13 - Set Baud Rate.
- //
- SetBaudRate()
- {
- short baudConst;
-
- baudConst = (SNBCLOCK / (32 * csStuff[1])) - 2;
- G->baudLow = baudConst & 0xFF;
- G->baudHigh = (baudConst >> 8) & 0xFF;
- InitSCC();
- }
-
- //
- // Control 16 - Set Misc. Options.
- //
- SetMiscOpt()
- {
- G->ctlOptions = (csStuff[1] >> 8) & 0xFF;
- }
-
- //
- // Control 17 - Assert DTR.
- //
- AssertDTR()
- {
- short s;
-
- s = Spl(7);
- G->flowOff &= ~0x40;
- *SCCControl = 0x05;
- *SCCControl = G->lastWR5 = G->lastWR5 | 0x80;
- (void)Spl(s);
- }
-
-
- //
- // Control 18 - Negate DTR.
- //
- NegateDTR()
- {
- short s;
-
- s = Spl(7);
- G->flowOff |= 0x40;
- *SCCControl = 0x05;
- *SCCControl = G->lastWR5 = G->lastWR5 & ~0x80;
- (void)Spl(s);
- }
-
- //
- // Control 19 - Set PE char.
- //
- SetPEChar()
- {
- short s;
-
- s = Spl(7);
- G->peChar = (csStuff[1] >> 8) & 0xFF;
- G->altChar = csStuff[1] & 0x7F;
- (void)Spl(s);
- }
-
- //
- // Control 20 - Set PE & Alt chars.
- //
- SetPEAltChar()
- {
- short s;
-
- s = Spl(7);
- G->peChar = (csStuff[1] >> 8) & 0xFF;
- G->altChar = csStuff[1] & 0xFF;
- (void)Spl(s);
- }
-
- //
- // Control 21 - Force XOff.
- //
- ForceXOff()
- {
- G->xOffFlag = 1;
- }
-
- //
- // Control 22 - Unconditionally clear XOff.
- //
- ClearXOff()
- {
- short s;
-
- s = Spl(7);
- G->xOffFlag = 0;
- tbeint();
- (void)Spl(s);
- }
-
- //
- // Control 23 - Send XOn if XOff last sent. Clear FlowOff State.
- //
- SendXOnIff()
- {
- short s;
-
- s = Spl(7);
- if (G->flowOff & 0x80)
- {
- G->flowOff &= 0x7F;
- if (!G->sendXOnff)
- {
- G->sendXOnff = G->xOnChar;
- if (!G->moreTx)
- tbeint();
- }
- else
- G->sendXOnff = 0;
- }
- (void)Spl(s);
- }
-
- //
- // Control 24 - Unconditionally Send XOn. Clear FlowOff State.
- //
- SendXOn()
- {
- short s;
-
- s = Spl(7);
- G->flowOff &= 0x7F;
- G->sendXOnff = G->xOnChar;
- if (!G->moreTx)
- tbeint();
- (void)Spl(s);
- }
-
- //
- // Control 25 - Send XOff if XOn last sent. Set FlowOff State.
- //
- SendXOffIff()
- {
- short s;
-
- s = Spl(7);
- if (!(G->flowOff & 0x80))
- {
- G->flowOff |= 0x8F;
- if (!G->sendXOnff)
- {
- G->sendXOnff = G->xOffChar;
- if (!G->moreTx)
- tbeint();
- }
- else
- G->sendXOnff = 0;
- }
- (void)Spl(s);
- }
-
- //
- // Control 26 - Unconditionally Send XOff. Set FlowOff State.
- //
- SendXOff()
- {
- short s;
-
- s = Spl(7);
- G->flowOff |= 0x80;
- G->sendXOnff = G->xOffChar;
- if (!G->moreTx)
- tbeint();
- (void)Spl(s);
- }
-
- //
- // Control 27 - Reset SCC.
- //
- ResetSCC()
- {
- short s;
-
- s = Spl(7);
- *SCCControl = 0x09;
- #ifdef PORTA
- *SCCControl = 0x80;
- #endif
- #ifdef PORTB
- *SCCControl = 0x40;
- #endif
- (void)Spl(s);
- }
-
-
- //
- // InitSCC - Utility to reset and reinitialize SCC.
- //
-
- InitSCC()
- {
- short s;
-
- s = Spl(7);
- *SCCControl = 0x09;
- #ifdef PORTA
- *SCCControl = 0x80;
- #endif
- #ifdef PORTB
- *SCCControl = 0x40;
- #endif
- *SCCControl = 0x04;
- *SCCControl = G->lastWR4;
- *SCCControl = 0x01;
- *SCCControl = 0x04;
- *SCCControl = 0x03;
- *SCCControl = G->lastWR3 & ~1;
- *SCCControl = 0x05;
- *SCCControl = G->lastWR5 & ~0x8A;
- *SCCControl = 0x09;
- *SCCControl = 0x01;
- *SCCControl = 0x0A;
- *SCCControl = 0x00;
- *SCCControl = 0x0B;
- *SCCControl = 0x50;
- *SCCControl = 0x0C;
- *SCCControl = G->baudLow;
- *SCCControl = 0x0D;
- *SCCControl = G->baudHigh;
- *SCCControl = 0x0E;
- *SCCControl = 0x02;
- *SCCControl = 0x03;
- *SCCControl = G->lastWR3;
- *SCCControl = 0x05;
- *SCCControl = G->lastWR5;
- *SCCControl = 0x0E;
- *SCCControl = 0x03;
- *SCCControl = 0x0F;
- *SCCControl = 0xA0;
- *SCCControl = 0x01;
- *SCCControl = 0x17;
- *SCCControl = 0x09;
- *SCCControl = 0x09;
- (void)Spl(s);
- }